Day 1 (Foundational Large Language Models & Prompt Engineering)
Today you’ll explore the evolution of LLMs, from transformers to techniques like fine-tuning and inference acceleration. You’ll also get trained in the art of prompt engineering for optimal LLM interaction.
The code lab will walk you through getting started with the Gemini API and cover several prompt techniques and how different parameters impact the prompts.
1. Complete the Intro Unit: “Foundational Large Language Models”, which is:
1. Listen to the summary podcast episode for this unit (created by NotebookLM). https://youtu.be/mQDlCZZsOyo
2. Complete Unit 1 – “Prompt Engineering”, which is:
1. Listen to the summary podcast episode for this unit (created by NotebookLM). https://youtu.be/F_hJ2Ey4BNc
半分くらい読んでるtakker.icon
意外と知らないことがあって興味深い
おそらく当たり前過ぎて説明がないんだと思う
2週目くらいに自分の知識を整理するときにでも、/work4aiにページを生やしていきたい 3. Complete this code lab on Kaggle where you’ll learn prompting fundamentals. Make sure you phone verify your account before starting, it's necessary for the code labs. code labをcopy & editしたtakker.icon
編集と実行ができるようになった
https://gyazo.com/6d6c1cc6147e48a007c343f8dcfb5555
発行した
https://gyazo.com/81f14c2b228dad7edfd1041ece1fc995
保存すると、このようにcode snippetが出てくる
https://gyazo.com/04ca9d50b0e6943ebcd096f4d02a2d9e
下にあったコードブロックを実行してみた
エラーになった。
前の方にあったコードブロックを飛ばして実行したから、そりゃそうなる
https://gyazo.com/e0ec8c85d125ac4877a819b746c1aa2d
多分UIはJupyter Notebookなんだろうけど、いかんせんnotebookをほとんど使ったことがないので、うまい使い方がよくわからないtakker.icon 以前のblocksを全部順に実行するコマンドRun > Run beforeがあった。これを使う
キーボードショートカットはなかった。
正常に実行された!
Run your first prompt
うごいた!
https://gyazo.com/4565f5cc1df554c8d5b52acca4ab17e2
すこしいじってみる
code:py
flash = genai.GenerativeModel('gemini-1.5-flash')
response = flash.generate_content("Explain AI to me like I'm a kid in Japanese.")
print(response.text)
日本語で話してくれた
なんか謎のローマ字起こしも加わってるが……まあいいや
code:output
ねえ、知ってる? AIって言うのがいるんだよ! AIはね、まるで賢いお友達みたいなんだ。
(Nee, shitteiru? AI tte iu no ga iru nda yo! AI wa ne, marude kashikoi o-tomodachi mitai nan da.) (Hey, do you know? There's something called AI! AI is like a smart friend.)
例えばね、AIは「猫の写真を見せて!」って言ったら、猫の写真をいっぱい見せてくれるんだよ。 自分で考えて、選んで見せてくれるんだ! すごいよね?
そうなんだ!すご~い!takker.icon
code:output
(Tatteiba ne, AI wa "neko no shashin o misete!" tte ittara, neko no shashin o ippai misete kureru nda yo. Jibun de kangaete, erande misete kureru nda! Sugoi yo ne?) (For example, if you tell AI "Show me pictures of cats!", it shows you lots of cat pictures. It thinks and chooses them by itself! Amazing, right?)
あとね、AIはゲームも上手だよ! 難しいゲームでも、たくさん練習して上手になるんだ。 まるで人間みたい!
(Ato ne, AI wa ge-mu mo jouzu da yo! Muzukashii ge-mu demo, takusan renshuu shite jouzu ni naru nda. Marude ningen mitai!) (Also, AI is good at games! Even difficult games, it gets good at them by practicing a lot. Just like a human!)
でもね、AIはまだ赤ちゃんみたいなところもあるんだ。 全部が全部、完璧にできるわけじゃないんだよ。 だから、人間がAIに教えてあげたり、手伝ってあげたりすることもあるんだよ。
(Demo ne, AI wa mada akachan mitai na tokoro mo aru nda. Zenbu ga zenbu, kanpeki ni dekiru wake ja nai nda yo. Dakara, ningen ga AI ni oshiete age tari, tasukete age tari suru koto mo aru nda yo.) (But, AI is still like a baby in some ways. It can't do everything perfectly. So, humans sometimes teach and help AI.)
AIはこれからもっともっと賢くなっていくと思うよ! 楽しみだね!
(AI wa kore kara motto motto kashikoku natte iku to omou yo! Tanoshimi da ne!) (I think AI will become even smarter from now on! I'm looking forward to it!)
うん!楽しみ!takker.icon
Start a chat
multi-turnなコードの例
https://gyazo.com/b4dc24138f7181a7301f3ca9cdd5d799
ところでKaggleのnotebookってvscodeで動かせないかなtakker.icon 多分拡張機能があるはず
ないみたい
今のところweb browserでやっても困らないから、このままweb browserでやろう
あとpythonではなくTypeScriptで動かしたい
無理そうtakker.icon
pythonかRしか対応してない
もちろんgeminiのtypescript API clientはある
Choose a model
genai.list_models()で利用可能なmodelsを取得できる
出力の文体がちょっと変わった
Explore generation parameters
max_output_tokensでLLMの出力サイズを制限できる
制限を超えると、出力が途中で打ち切られる
https://gyazo.com/f1c635d554c7a04daac025e801ddca84
code:py
# When running lots of queries, it's a good practice to use a retry policy so your code
# automatically retries when hitting Resource Exhausted (quota limit) errors.
retry_policy = {
"retry": retry.Retry(predicate=retry.if_transient_error, initial=10, multiplier=1.5, timeout=300)
}
temperature=0.0だとおんなじ回答ばかり返ってくることを確認した
Top-K and top-P
正直違いはまだ実感できていないtakker.icon
wogikaze.iconprivateからcopy
トークンの生起確率分布に従いランダムに選択
だいたい多様性
pとkは、絶対値か相対値かの違いくらいかなtakker.icon
Prompting
configでJSON出力などを指定できる
Code Prompting
適当に実行した
4. Read this case study to learn how a leading bank leveraged advanced prompt engineering and other contents discussed in assignments of day 1 to automate their financial advisory workflows, achieving significant productivity gains. ざっと目を通した
銀行の事例
3. Watch the YouTube livestream recording.
Paige Bailey will be joined by expert speakers from Google - Mohammadamin Barekatain, Lee Boonstra, Logan Kilpatrick, Daniel Mankowitz, Majd Merey Al, Anant Nawalgaria, Aliaksei Severyn and Chuck Sugnet to discuss today's readings and code labs. https://www.youtube.com/watch?v=kpRyiJUUFxY&list=PLqFaTIg4myu-b1PlxitQdY0UYIbys-2es&index=1&t=13s